package Win

import (
	"net/http"
)

/**
 * @Author: bytedance
 * @Description: 描述
 * @File: Win
 * @Date: 2022/5/18 10:15 PM
 * @Software : GoLand
 */
type HandlerFunc func(*Context)
type Engine struct {
	router *router
}

func New() *Engine {
	return &Engine{router: newRouter()}
}

func (e *Engine) addRoute(method string, route string, handlerFunc HandlerFunc) {
	e.router.addRoute(method, route, handlerFunc)
}
func (e *Engine) GET(route string, handlerFunc HandlerFunc) {
	e.router.addRoute("GET", route, handlerFunc)
}

func (e *Engine) POST(route string, handlerFunc HandlerFunc) {
	e.router.addRoute("POST", route, handlerFunc)
}
func (e *Engine) Run(addr string) (err error) {
	return http.ListenAndServe(addr, e)
}
func (e *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	c := newContext(w, r)
	e.router.handle(c)
}
